/**
 * 跨页面通信
 */
const ServiceCenter = {}
const ServiceName = {
  licenseCallback: 'licenseCallback',
  licenseInitData: 'licenseInitData',
  qualificationCallback: 'qualificationCallback',
  qualificationInitData: 'qualificationInitData',
  expandInfoCallback: 'expandInfoCallback',
  expandInfoInitData: 'expandInfoInitData',
  legalInfoInitData: 'legalInfoInitData',
  legalInfoCallback: 'legalInfoCallback',
  selectPageCallback: 'selectPageCallback',
  selectPageRequestFuncCallback: 'selectPageRequestFuncCallback',
  selectTreeCallback: 'selectTreeCallback',
  setDefaultExpandData: 'setDefaultExpandData',
  //企业商户签约
  baseInfoInitData: 'baseInfoInitData',
  baseInfoCallback: 'baseInfoCallback',
  bankInfoInitData: 'bankInfoInitData',
  bankInfoCallback: 'bankInfoCallback',
  shareholderInfoInitData: 'shareholderInfoInitData',
  shareholderInfoCallback: 'shareholderInfoCallback',
  //产品订购->详情传参
  productDetailInitData: 'productDetailInitData',
  productDetailCallback: 'productDetailCallback',
  //创建->产品列表
  productListInitData: 'productListInitData',
  productListCallback: 'productListCallback',
  //聚合支付信息详情
  longLinkInitData:'longLinkInitData',
  terminalInfoList:'terminalInfoList',
  terminalInfoInit:'terminalInfoInit',

}

function registerService(serviceName, method) {
  ServiceCenter[serviceName] = method
}

function removeService(serviceName) {
  delete ServiceCenter[serviceName]
}

//支持多参数
function callService(serviceName, param) {
  if (typeof ServiceCenter[serviceName] !== 'function') return false
  let p = []
  for(let i = 1; i < arguments.length; i++) {
    p.push(arguments[i])
  }
  let ret = ServiceCenter[serviceName](...p)
  return ret || true
}

module.exports = {
  ServiceName,
  registerService,
  removeService,
  callService
}